const request = require('../../utils/request')

Page({
  data: {
  },
  onLoad(opt) {
    let serviceInfo = wx.getStorageSync('serviceInfo')
    this.setData({
      serviceAddress: serviceInfo.serviceAddress,
      interface: serviceInfo.interface
    })
    this.setData({
      interface: 'getAreaInfoByT'
    })
  },
  formSubmit(e) {
    console.log('ee', e);
    let serviceAddress =  e.detail.value.serviceAddress
    if (serviceAddress.slice(-1) !== '/') {
      serviceAddress += '/'
    }
    let interfaceInfo = e.detail.value.interface
    let _this = this
    let serviceInfo = {
      serviceAddress: serviceAddress,
      interfaceInfo: interfaceInfo
    }
    if (serviceInfo.serviceAddress && serviceInfo.interfaceInfo) {
      wx.setStorageSync('serviceInfo', serviceInfo)
      this.successResult('OK')
      setTimeout(() => {
        _this.back()
      }, 1500);
    } else {
      this.errorResult('参数为空')
    }
  },

  errorResult(errorInfo) {
    wx.showToast({
      title: errorInfo,
      icon: 'error',
      duration: 2000
    })
  },

  successResult(successInfo) {
    wx.showToast({
      title: successInfo,
      icon: 'success',
      duration: 2000
    })
  },

  back() {
    wx.navigateBack({
      delta: 1
    });
  }
})